home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 5 / powers of 3 < prev   
Text File  |  1994-04-16  |  3KB  |  139 lines

  1. ; This fiendishly-difficult-to-write program computes powers of
  2. ; three up to "any" number of digits.  It starts with N1=3,
  3. ; copies N1 to N2, then adds N2 to N1 twice and repeats this
  4. ; forever.  Note that this program is NOT restricted to 16-bit
  5. ; numbers; it can work with numbers with many more bits than
  6. ; that spread out over a long sequence of memory locations.
  7. ; This program uses two such multi-location numbers, one
  8. ; at location 500 and one at location 1000.  The program
  9. ; itself loads starting at location 0.
  10.  
  11. ; The main point of giving you this computation is to let
  12. ; you "see" what a real computation might look like.
  13. ; Watch this at "Fastest" speed with Memory Display set to
  14. ; "Graphics".  The program is a random scattering of bits at
  15. ; the top of the memory.  Several locations just after the
  16. ; program hold data that is used continually during the
  17. ; computation.  You will see the bits in these locations
  18. ; dancing the whole time the program is running.  You will
  19. ; also see the multi-location number at the bottom of the
  20. ; screen fill up more and more locations as it grows larger
  21. ; and larger.
  22.  
  23. 1024# 0  ; The notation "1024#" tells the assembler to
  24.          ; repeat the next item 1024 times in memory.
  25.          ; In this case, 1024 zeros are stored in memory,
  26.          ; effectively clearing out anything that might
  27.          ; have been there before.
  28.  
  29. @PC 0    ; Store a zero into the PC
  30.  
  31. @0       ; Start loading instructions at location 0
  32.  
  33.        lod-c 3
  34.        sto N1
  35.        lod-c 1
  36.        sto ct1
  37.  
  38. copy:  lod ct1
  39.        sto ct2
  40.        sto ct
  41.        lod-c N1
  42.        sto src
  43.        lod-c N2
  44.        sto dest
  45. c1:    lod-i src
  46.        sto-i dest
  47.        lod ct
  48.        dec
  49.        jmz sum
  50.        sto ct
  51.        lod src
  52.        dec
  53.        sto src
  54.        lod dest
  55.        dec
  56.        sto dest
  57.        jmp c1
  58.  
  59. sum:   lod ct2
  60.        sto ct
  61.        lod-c N2
  62.        sto src
  63.        lod-c N1
  64.        sto dest
  65.        lod-c 0
  66.        sto carryQ
  67. s1:    lod-i dest
  68.        add-i src
  69.        sto-i dest
  70.        jmf cr1
  71. s2:    lod-i dest
  72.        add-i src
  73.        sto-i dest
  74.        jmf cr2
  75. s3:    lod ct
  76.        dec
  77.        jmz copy
  78.        sto ct
  79.        lod src
  80.        dec
  81.        sto src
  82.        lod dest
  83.        dec
  84.        sto dest
  85.        jmp s1
  86.  
  87. cr1:   lod-c s2
  88.        sto return
  89.        jmp add1
  90.  
  91. cr2:   lod-c s3
  92.        sto return
  93.        jmp add1
  94.  
  95. add1:  lod ct
  96.        sto aCt
  97.        lod dest
  98.        sto aDest
  99. a1:    lod aDest
  100.        dec
  101.        sto aDest
  102.        lod aCt
  103.        dec
  104.        sto aCt
  105.        jmz advnc
  106.        lod-i aDest
  107.        add-c 1
  108.        sto-i aDest
  109.        jmf a1
  110.        jmp-i return
  111. advnc: lod carryQ
  112.        jmz adv1
  113.        lod-i aDest
  114.        add-c 1
  115.        sto-i aDest
  116.        jmp-i return
  117. adv1:  lod ct1
  118.        inc
  119.        sto ct1
  120.        lod-c 1
  121.        sto-i aDest
  122.        lod-c 1
  123.        sto carryQ
  124.        jmp-i return
  125.  
  126. return:data
  127. ct1:   data
  128. ct2:   data
  129. ct:    data
  130. src:   data
  131. dest:  data
  132. aCt:   data
  133. aDest: data
  134. carryQ:data
  135.  
  136. @500
  137. N1: data
  138. @1000
  139. N2: data